package com.factory.test.util;


import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Handler;

import com.factory.test.R;

import java.util.HashMap;

/**
 * 声音提示工具类
 */
public class SoundManager {

    public SoundPool soundPool;
    public HashMap<Integer, Integer> soundMap;


    protected Context context;
    public SoundManager(Context context) {
        this.context = context;
        soundMap = new HashMap<Integer, Integer>();
        soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

        soundMap.put(100, soundPool.load(context, R.raw.tip_success, 1));
        soundMap.put(101, soundPool.load(context, R.raw.tip_fail, 1));
        soundMap.put(102, soundPool.load(context, R.raw.tip_warning, 1));
        soundMap.put(103, soundPool.load(context, R.raw.beep, 1));
        soundMap.put(104, soundPool.load(context, R.raw.doorbell, 1));
        soundMap.put(105, soundPool.load(context, R.raw.take, 1));
    }

    public void playSuccess(){
        soundPool.play(soundMap.get(100), 1, 1, 0, 0, 1);
    }

    public void playFail(){
        soundPool.play(soundMap.get(101), 1, 1, 0, 0, 1);
    }

    public void playWarning(){
        soundPool.play(soundMap.get(102), 1, 1, 0, 0, 1);
    }

    /**
     * 刷卡的声音
     */
    public void playBeep(){
        soundPool.play(soundMap.get(103), 1, 1, 0, 0, 1);
    }

    /**
     * 播放拍照
     */
    public void playTake() {
        soundPool.play(soundMap.get(105), 1, 1, 0, 0, 1);
    }

    /**
     * 门铃的声音
     */
    public void playDoorbell(Handler handler){
        //soundPool.play(soundMap.get(104), 1, 1, 0, 0, 1);     //
        //DoorbellUtil.playDoorbell(handler); //D1 口拉高电平播放门铃
    }

    public void release(){
        try {
            soundPool.release();
        } catch (Exception e) {
            //e.printStackTrace();
        }
    }
}
